package enterprise.manage.entity;

import org.hibernate.annotations.Where;

import javax.persistence.*;
import java.util.Date;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: zhenmingyue
 * Date: 2011-7-4 18:02:36
 * Desc:
 * For :
 */
@Entity
@org.hibernate.annotations.Entity(dynamicInsert = true, dynamicUpdate = true)
@Table(schema = "mg",name = "role")
public class Role {
    private Long id;
    private String roleName;
    private String roleAlias;
    private Date createTime;
    private Integer roleLevel;
    private String remark;
    private Integer deleted;
    private List<Authority> authorityList;

//    private List<User> users;
    @Id
    @Column(name = "id")
    @GeneratedValue(strategy = GenerationType.AUTO)
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getRoleName() {
        return roleName;
    }

    public void setRoleName(String roleName) {
        this.roleName = roleName;
    }

    public String getRoleAlias() {
        return roleAlias;
    }

    public void setRoleAlias(String roleAlias) {
        this.roleAlias = roleAlias;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Integer getRoleLevel() {
        return roleLevel;
    }

    public void setRoleLevel(Integer roleLevel) {
        this.roleLevel = roleLevel;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public Integer getDeleted() {
        return deleted;
    }

    public void setDeleted(Integer deleted) {
        this.deleted = deleted;
    }
   @ManyToMany(targetEntity=Authority.class, cascade={CascadeType.ALL},fetch = FetchType.LAZY)
   @JoinTable( name="role_authority", //中间表名
        joinColumns=@JoinColumn(name="roleId"),inverseJoinColumns=@JoinColumn(name="authorityId")
   )
    public List<Authority> getAuthorityList() {
        return authorityList;
    }

    public void setAuthorityList(List<Authority> authorityList) {
        this.authorityList = authorityList;
    }
//    @ManyToMany( cascade = {CascadeType.ALL},mappedBy = "roles",//相等于inverse   //如果不加这一句，会多生成一个中间表
//                targetEntity = User.class )
//    public List<User> getUsers() {
//        return users;
//    }
//
//    public void setUsers(List<User> users) {
//        this.users = users;
//    }
}
